package org.jeecg.modules.engine.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import me.zhyd.oauth.utils.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.CommonSendStatus;
import org.jeecg.common.system.base.service.impl.JeecgServiceImpl;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.modules.content.entity.ContentInfo;
import org.jeecg.modules.content.service.IContentInfoService;
import org.jeecg.modules.engine.service.IWorkflowEngineService;
import org.jeecg.modules.system.entity.SysAnnouncement;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.service.ISysAnnouncementService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.task.entity.*;
import org.jeecg.modules.task.mapper.TaskInfoBaseMapper;
import org.jeecg.modules.task.service.*;
import org.jeecg.modules.task.service.impl.TaskWorkflowAssignDepartServiceImpl;
import org.jeecg.modules.workflow.entity.*;
import org.jeecg.modules.workflow.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 工作流引擎
 * @Author: wufanxin
 * @Date:  2021-06-15
 * @Version: V1.0
 */
@Service
public class WorkflowEngineServiceImpl implements IWorkflowEngineService {

    @Autowired
    ITaskInfoBaseService taskInfoBaseService;

    @Autowired
    private ITaskWorkflowMainService taskWorkflowMainService;

    @Autowired
    private ITaskWorkflowHoldService taskWorkflowHoldService;

    @Autowired
    private ITaskWorkflowStepService taskWorkflowStepService;

    @Autowired
    private IWorkFlowChildNodeService childNodeService;

    @Autowired
    private IWorkFlowParentNodeService parentNodeService;

    @Autowired
    private IWorkFlowChildNodeAssignPersonService wfUserAssignService;

    @Autowired
    private IWorkFlowChildNodeAssignDeptService wfDeptAssignService;
    @Autowired
    private IWorkFlowChildNodeAssignRoleService wfRoleAssignService;


    @Autowired
    private ITaskWorkflowAssignDepartService departAssignService;

    @Autowired
    private ITaskWorkflowAssignRoleService roleAssignService;

    @Autowired
    private ITaskWorkflowAssignUserService userAssignService;

    @Autowired
    private ITaskOperationService operationService;


    @Autowired
    ISysAnnouncementService sysAnnouncementService;

    @Resource
    SysDepartMapper sysDepartMapper;

    @Autowired
    IContentInfoService contentInfoService;

    @Override
    public void startWorkFlow(String workflowId, String taskNo,String userId,String userName) {
        //开启一个工作流
        //流转工作流至第一节点
        //获取到第一个一级节点
        QueryWrapper<WorkFlowParentNode> parentNodeQueryWrapper = new QueryWrapper<>();
        parentNodeQueryWrapper.eq("workflow_id",workflowId);
        parentNodeQueryWrapper.orderByAsc("sort");
        List<WorkFlowParentNode> parentList =parentNodeService.list(parentNodeQueryWrapper);
        WorkFlowParentNode firstParentNode = parentList.get(0);

        //查询该一级节点名下所有的子节点
        QueryWrapper<WorkFlowChildNode> childNodes  = new QueryWrapper<>();
        childNodes.eq("parent_node_id",firstParentNode.getNodeId());
        List<WorkFlowChildNode> childList = childNodeService.list(childNodes);
        //循环二级节点，根据二级节点中配置到人还是组，将任务分配过去
        clearAndResetTaskAssign(taskNo,childList,userId);

        //更新TaskWorkflowMain的一级节点
        TaskWorkflowMain workflowMain = new TaskWorkflowMain();
        workflowMain.setDealPersonId(userId);
        workflowMain.setWorkflowId(workflowId);
        workflowMain.setTaskNo(taskNo);
        workflowMain.setCurrentNodeId(firstParentNode.getNodeId());
        taskWorkflowMainService.save(workflowMain);

        //插入流转详情日志
        //创建任务的时候不需要插入
        TaskWorkflowStep stepInfo =new TaskWorkflowStep();
        stepInfo.setChildNodeId("");
        stepInfo.setDealUserId(userId);
        stepInfo.setParentNodeId("");
        stepInfo.setTaskNo(taskNo);
        stepInfo.setOprate("创建任务");
        stepInfo.setRemark("用户:" + userName + "创建任务");
        taskWorkflowStepService.save(stepInfo);
    }

    @Override
    public void grant(String taskNo, String childNodeId, String userId,String grantUserId,String grantUserName,String userName) {

        //授权的时候，节点不流转，但是换分配人
        //获取这个节点的基础信息
        QueryWrapper<WorkFlowChildNode> childNodeWrapper = new QueryWrapper<>();
        childNodeWrapper.eq("node_id",childNodeId);
        WorkFlowChildNode childNode = childNodeService.getOne(childNodeWrapper);
        //第一步。先清除该任务在该节点的分配信息，然后授权给本人

        //不管原来是分配部门还是人，一旦授权，则全部重新分配给人，所以要清除部门和人的原有分配
        clearTaskAssign(taskNo);

        TaskWorkflowAssignUser grantAssign = new TaskWorkflowAssignUser();
        grantAssign.setAssignUserId(grantUserId);
        grantAssign.setTaskNo(taskNo);
        grantAssign.setNodeId(childNode.getNodeId());
        userAssignService.save(grantAssign);

        //插入流转详情日志
        TaskWorkflowStep stepInfo = new TaskWorkflowStep();
        stepInfo.setChildNodeId(childNodeId);
        stepInfo.setDealUserId(userId);
        stepInfo.setParentNodeId(childNode.getParentNodeId());
        stepInfo.setTaskNo(taskNo);
        stepInfo.setOprate("授权");
        stepInfo.setRemark("用户:"+userName+" 授权给："+grantUserName);

        taskWorkflowStepService.save(stepInfo);

    }
    @Override
    public void grantReverse(String taskNo, String childNodeId, String userId,String grantUserId,String grantUserName,String userName) {

        //授权的时候，节点不流转，但是换分配人
        //获取这个节点的基础信息
        QueryWrapper<WorkFlowChildNode> childNodeWrapper = new QueryWrapper<>();
        childNodeWrapper.eq("node_id",childNodeId);
        WorkFlowChildNode childNode = childNodeService.getOne(childNodeWrapper);
        //第一步。先清除该任务在该节点的分配信息，然后授权给本人

        //不管原来是分配部门还是人，一旦授权，则全部重新分配给人，所以要清除部门和人的原有分配
        clearTaskAssign(taskNo);

        TaskWorkflowAssignUser grantAssign = new TaskWorkflowAssignUser();
        grantAssign.setAssignUserId(grantUserId);
        grantAssign.setTaskNo(taskNo);
        grantAssign.setNodeId(childNode.getNodeId());
        userAssignService.save(grantAssign);

        //插入流转详情日志
        TaskWorkflowStep stepInfo = new TaskWorkflowStep();
        stepInfo.setChildNodeId(childNodeId);
        stepInfo.setDealUserId(userId);
        stepInfo.setParentNodeId(childNode.getParentNodeId());
        stepInfo.setTaskNo(taskNo);
        stepInfo.setOprate("撤回");
        stepInfo.setRemark("用户:"+userName+" 撤回，流转给："+grantUserName);

        taskWorkflowStepService.save(stepInfo);

    }
    @Override
    public void grantTaskBoost(String taskNo, String childNodeId, String userId,String grantUserId,String grantUserName,String userName) {
        //加签的时候，节点不流转，但是换分配人
        //获取这个节点的基础信息
        QueryWrapper<WorkFlowChildNode> childNodeWrapper = new QueryWrapper<>();
        childNodeWrapper.eq("node_id",childNodeId);
        WorkFlowChildNode childNode = childNodeService.getOne(childNodeWrapper);
        //第一步。先清除该任务在该节点的分配信息，然后授权给本人

        //不管原来是分配部门还是人，一旦授权，则全部重新分配给人，所以要清除部门和人的原有分配
        clearTaskAssign(taskNo);

        TaskWorkflowAssignUser grantAssign = new TaskWorkflowAssignUser();
        grantAssign.setAssignUserId(grantUserId);
        grantAssign.setTaskNo(taskNo);
        grantAssign.setNodeId(childNode.getNodeId());
        userAssignService.save(grantAssign);

        //插入流转详情日志
        TaskWorkflowStep stepInfo = new TaskWorkflowStep();
        stepInfo.setChildNodeId(childNodeId);
        stepInfo.setDealUserId(userId);
        stepInfo.setParentNodeId(childNode.getParentNodeId());
        stepInfo.setTaskNo(taskNo);
        stepInfo.setOprate("加签");
        stepInfo.setRemark("用户:"+userName+" 提交给："+grantUserName+"进行加签");

        taskWorkflowStepService.save(stepInfo);

    }

    @Autowired
    private ISysUserService sysUserService;
    @Override
    public void process(String taskNo, String childNodeId, String userId,String userName) {
        TaskWorkflowStep stepInfo = new TaskWorkflowStep();

        //获取这个节点的基础信息
        QueryWrapper<WorkFlowChildNode> childNodeWrapper = new QueryWrapper<>();
        childNodeWrapper.eq("node_id",childNodeId);
        WorkFlowChildNode childNode = childNodeService.getOne(childNodeWrapper);

        QueryWrapper<WorkFlowParentNode> parentNodeWrapper = new QueryWrapper<>();
        parentNodeWrapper.eq("node_id",childNode.getParentNodeId());
        WorkFlowParentNode parentNode = parentNodeService.getOne(parentNodeWrapper);

        //查询当前二级节点的上级节点，看是否有或/与关系
        boolean process = true;
        //如果是或关系，继续处理提交
        if(parentNode.getOpType().equals("1")){
            //与关系，先插入处理处理等待的表，
            TaskWorkflowHold hold = new TaskWorkflowHold();
            hold.setChildNodeId(childNode.getNodeId());
            hold.setParentNodeId(childNode.getParentNodeId());
            hold.setTaskNo(taskNo);
            taskWorkflowHoldService.save(hold);
            //然后查询等待表中的数据和子节点个数
            QueryWrapper<TaskWorkflowHold> holdQueryWrapper = new QueryWrapper<>();
            holdQueryWrapper.eq("task_no",taskNo);
            holdQueryWrapper.eq("parent_node_id",childNode.getParentNodeId());
            List<TaskWorkflowHold> holdList = taskWorkflowHoldService.list(holdQueryWrapper);
            //如果相同，则可以继续
            QueryWrapper<WorkFlowChildNode> nowChildWrapper = new QueryWrapper<>();
            nowChildWrapper.eq("parent_node_id",childNode.getParentNodeId());
            List<WorkFlowChildNode> nowChildList = childNodeService.list(nowChildWrapper);
            if(holdList.size() < nowChildList.size() ){
                process = false;
            }
        }

        if(process) {
            //如果继续执行到下一步
            //获取下一个一级节点
            QueryWrapper<WorkFlowParentNode> nextParentNodeWrapper = new QueryWrapper<>();
            nextParentNodeWrapper.eq("workflow_id", parentNode.getWorkflowId());
            nextParentNodeWrapper.gt("sort", parentNode.getSort());
            nextParentNodeWrapper.last("limit 1");
            nextParentNodeWrapper.orderByAsc("sort");
            WorkFlowParentNode nextParentNode = parentNodeService.getOne(nextParentNodeWrapper);

            String mainNodeId = "";
            String oprate = "提交下一节点";
            String remark = "";
            if(null != nextParentNode){
                //获取下一个一级节点对应的所有二级节点
                QueryWrapper<WorkFlowChildNode> nextChildNodeWrapper = new QueryWrapper<>();
                nextChildNodeWrapper.eq("parent_node_id", nextParentNode.getNodeId());
                List<WorkFlowChildNode> nextChildList = childNodeService.list(nextChildNodeWrapper);

                //循环下一子节点组，循环插入任务分配
                String tempUserId = userId;

                clearAndResetTaskAssign(taskNo, nextChildList,tempUserId);

                //插入流转详情日志
                remark = "用户:" + userName + " 提交到下一节点：" + nextParentNode.getNodeName();
                mainNodeId=nextParentNode.getNodeId();
            }else{
                //如果下一个节点为null，则任务结束
                //清除分配数据
                clearTaskAssign(taskNo);
                //更新main，currentid设置成1
                mainNodeId = "1";
                //插入流转日志，
                oprate="任务结束";
                remark="用户:" + userName + " 办结，结束任务";
//                mainNodeId=parentNode.getNodeId();
                mainNodeId="";
                //在最后一个节点的时候 更新任务内容状态
                operationService.updateTaskContentAndActivityRelease(taskNo);
                //更新任务状态
                UpdateWrapper<TaskInfoBase> taskInfoBaseUpdateWrapper = new UpdateWrapper<>();
                taskInfoBaseUpdateWrapper.set("state","1");
                taskInfoBaseUpdateWrapper.set("finish_time",new Date());
                taskInfoBaseUpdateWrapper.eq("task_no",taskNo);
                taskInfoBaseService.update(taskInfoBaseUpdateWrapper);
            }

            //插入任务主流程表
            UpdateWrapper<TaskWorkflowMain> mainUpdateWrapper =new UpdateWrapper<>();
            mainUpdateWrapper.set("current_node_id",mainNodeId);
            mainUpdateWrapper.set("workflow_id",parentNode.getWorkflowId());
            mainUpdateWrapper.set("deal_person_id",userId);
            mainUpdateWrapper.eq("task_no",taskNo);
            taskWorkflowMainService.update(mainUpdateWrapper);

            stepInfo.setChildNodeId(childNode.getNodeId());
            stepInfo.setDealUserId(userId);
            stepInfo.setParentNodeId(childNode.getParentNodeId());
            stepInfo.setTaskNo(taskNo);
            stepInfo.setOprate(oprate);
            stepInfo.setRemark(remark);

        }else{
            //不往下的情况下，将该节点的分配清除掉
            UpdateWrapper<TaskWorkflowAssignDepert> departupdateWrapper =  new UpdateWrapper<>();
            departupdateWrapper.set("assign_depart_id","");
            departupdateWrapper.eq("task_no",taskNo);
            departupdateWrapper.eq("node_id",childNode.getNodeId());
            departAssignService.update(departupdateWrapper);

            UpdateWrapper<TaskWorkflowAssignRole> roleUpdateWrapper =  new UpdateWrapper<>();
            roleUpdateWrapper.set("assign_role_id","");
            roleUpdateWrapper.eq("task_no",taskNo);
            roleUpdateWrapper.eq("node_id",childNode.getNodeId());
            roleAssignService.update(roleUpdateWrapper);

            UpdateWrapper<TaskWorkflowAssignUser> userUpdateWrapper = new UpdateWrapper<>();
            userUpdateWrapper.set("assign_user_id","");
            userUpdateWrapper.eq("task_no",taskNo);
            userUpdateWrapper.eq("node_id",childNode.getNodeId());
            userAssignService.update(userUpdateWrapper);
            //插入流转详情日志
            stepInfo.setChildNodeId(childNode.getNodeId());
            stepInfo.setDealUserId(userId);
            stepInfo.setParentNodeId(childNode.getParentNodeId());
            stepInfo.setTaskNo(taskNo);
            stepInfo.setOprate("已提交，等待流转到下一节点");
            stepInfo.setRemark("用户:" + userName + " 已提交，等待流转到下一节点");
        }

        taskWorkflowStepService.save(stepInfo);

    }

    @Override
    public int reject(String taskNo, String childNodeId, String userId, String userName,String remark) {
        int code = 200;
        //驳回时，根据childNodeId,先找到一级节点，然后找到一级节点配置退回节点
        QueryWrapper<WorkFlowChildNode> childNodeWrapper = new QueryWrapper<>();
        childNodeWrapper.eq("node_id",childNodeId);
        WorkFlowChildNode childNode = childNodeService.getOne(childNodeWrapper);

        QueryWrapper<WorkFlowParentNode> parentNodeWrapper = new QueryWrapper<>();
        parentNodeWrapper.eq("node_id",childNode.getParentNodeId());
        WorkFlowParentNode parentNode = parentNodeService.getOne(parentNodeWrapper);


        QueryWrapper<WorkFlowParentNode> backNodeWrapper = new QueryWrapper<>();
        //如果退回节点为空，告诉前端
        if(null == parentNode || StringUtils.isEmpty(parentNode.getBackNodeId())){
            return 202;
        }
        backNodeWrapper.eq("node_id",parentNode.getBackNodeId());
        WorkFlowParentNode backNode = parentNodeService.getOne(backNodeWrapper);

        QueryWrapper<WorkFlowChildNode> backChildNodeWrapper = new QueryWrapper<>();
        backChildNodeWrapper.eq("parent_node_id",backNode.getNodeId());
        List<WorkFlowChildNode> childList = childNodeService.list(backChildNodeWrapper);
        //清除现在节点的分配信息
        //根据上一节点配置重新分配信息
        clearAndResetTaskAssign(taskNo,childList,userId);
        //更新main
        UpdateWrapper<TaskWorkflowMain> mainUpdateWrapper =new UpdateWrapper<>();
        mainUpdateWrapper.set("current_node_id",backNode.getNodeId());
        mainUpdateWrapper.set("workflow_id",parentNode.getWorkflowId());
        mainUpdateWrapper.set("deal_person_id",userId);
        mainUpdateWrapper.eq("task_no",taskNo);
        taskWorkflowMainService.update(mainUpdateWrapper);
        //插入step
        TaskWorkflowStep stepInfo = new TaskWorkflowStep() ;
        stepInfo.setChildNodeId(childNodeId);
        stepInfo.setDealUserId(userId);
        stepInfo.setParentNodeId(childNode.getParentNodeId());
        stepInfo.setTaskNo(taskNo);
        stepInfo.setOprate("驳回");
        //查询驳回原因

        stepInfo.setRemark("用户:" + userName + "驳回，退回到"+backNode.getNodeName()+"节点,驳回原因："+remark);
        taskWorkflowStepService.save(stepInfo);
        return code;
    }

    /**
     * 清除任务分配
     * @param taskNo
     */
    private void clearTaskAssign(String taskNo){
        //清除现在的任务分配
        QueryWrapper<TaskWorkflowAssignDepert> departDeleteWrapper = new QueryWrapper<>();
        departDeleteWrapper.eq("task_no",taskNo);
        departAssignService.remove(departDeleteWrapper);

        //清除现在的任务分配
        QueryWrapper<TaskWorkflowAssignRole> roleDeleteWrapper = new QueryWrapper<>();
        roleDeleteWrapper.eq("task_no",taskNo);
        roleAssignService.remove(roleDeleteWrapper);

        QueryWrapper<TaskWorkflowAssignUser> departUserWrapper = new QueryWrapper<>();
        departUserWrapper.eq("task_no",taskNo);
        userAssignService.remove(departUserWrapper);
    }

    /**
     * 清除该任务下的任务分配，并将节点重新分配
     * @param taskNo
     * @param childList
     */
    private void clearAndResetTaskAssign(String taskNo,List<WorkFlowChildNode> childList,String userId){
        //清除现在的任务分配
        clearTaskAssign(taskNo);
        List<String> userIds = new ArrayList<>();

        //循环下一子节点组，循环插入任务分配
        childList.stream().forEach(child->{
            if(child.getAssignType().equals("0")){
                //分配部门
                QueryWrapper<WorkFlowChildNodeAssignDept> deptQueryWrapper = new QueryWrapper<>();
                deptQueryWrapper.eq("node_id",child.getNodeId());
                List<WorkFlowChildNodeAssignDept> deptAssignList = wfDeptAssignService.list(deptQueryWrapper);
                //存入task的分配信息
                List<TaskWorkflowAssignDepert> taskDeptAssignList = new ArrayList<>();
                deptAssignList.stream().forEach(item->{
                    TaskWorkflowAssignDepert temp = new TaskWorkflowAssignDepert();
                    temp.setAssignDepartId(item.getAssignInfo());
                    temp.setTaskNo(taskNo);
                    temp.setNodeId(child.getNodeId());
                    taskDeptAssignList.add(temp);
                    try{
                        //根据部门查询用户 item.getAssignInfo()
                        List<String> tempUserIds = sysDepartMapper.getUserIdBydepartId(item.getAssignInfo());
                        userIds.addAll(tempUserIds);
                    }catch (Exception e){

                    }
                });
                departAssignService.saveBatch(taskDeptAssignList);


                //分配角色
                QueryWrapper<WorkFlowChildNodeAssignRole> roleQueryWrapper = new QueryWrapper<>();
                roleQueryWrapper.eq("node_id",child.getNodeId());
                List<WorkFlowChildNodeAssignRole> roleAssignList = wfRoleAssignService.list(roleQueryWrapper);
                //存入task的分配信息
                List<TaskWorkflowAssignRole> taskRoleAssignList = new ArrayList<>();
                roleAssignList.stream().forEach(item->{
                    TaskWorkflowAssignRole temp = new TaskWorkflowAssignRole();
                    temp.setAssignRoleId(item.getAssignInfo());
                    temp.setTaskNo(taskNo);
                    temp.setNodeId(child.getNodeId());
                    taskRoleAssignList.add(temp);
                    userIds.add(item.getAssignInfo());

                });
                roleAssignService.saveBatch(taskRoleAssignList);



            }else if(child.getAssignType().equals("1")){
                //分配人
                QueryWrapper<WorkFlowChildNodeAssignPerson> userQueryWrapper = new QueryWrapper<>();
                userQueryWrapper.eq("node_id",child.getNodeId());
                List<WorkFlowChildNodeAssignPerson> userAssignList = wfUserAssignService.list(userQueryWrapper);
                //存入task的分配信息
                List<TaskWorkflowAssignUser> taskUserAssignList = new ArrayList<>();
                userAssignList.stream().forEach(item->{
                    TaskWorkflowAssignUser temp = new TaskWorkflowAssignUser();
                    temp.setAssignUserId(item.getAssignInfo());
                    temp.setTaskNo(taskNo);
                    temp.setNodeId(child.getNodeId());

                    taskUserAssignList.add(temp);
                });
                userAssignService.saveBatch(taskUserAssignList);
            }else if(child.getAssignType().equals("2")){
                    QueryWrapper<TaskInfoBase> taskInfoBaseQueryWrapper = new QueryWrapper<>();
                    taskInfoBaseQueryWrapper.eq("task_no",taskNo).last(" limit 1");
                    TaskInfoBase taskInfoBase = taskInfoBaseService.getOne(taskInfoBaseQueryWrapper);
                    SysUser sysUser1 = sysUserService.getUserByName(taskInfoBase.getCreateBy());

                //分配人
                QueryWrapper<WorkFlowChildNodeAssignPerson> userQueryWrapper = new QueryWrapper<>();
                userQueryWrapper.eq("node_id",child.getNodeId());
                List<TaskWorkflowAssignUser> taskUserAssignList = new ArrayList<>();
                //分配给自己
                TaskWorkflowAssignUser temp = new TaskWorkflowAssignUser();
                temp.setAssignUserId(sysUser1.getId());
                temp.setTaskNo(taskNo);
                temp.setNodeId(child.getNodeId());

                taskUserAssignList.add(temp);
                userAssignService.saveBatch(taskUserAssignList);
            }

            try{
                SysAnnouncement sysAnnouncement = new SysAnnouncement();
                sysAnnouncement.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
                sysAnnouncement.setSendStatus(CommonSendStatus.PUBLISHED_STATUS_1);//未发布
                sysAnnouncement.setMsgCategory("1");
                sysAnnouncement.setMsgType("USER");
                sysAnnouncement.setSendTime(new Date());
                sysAnnouncement.setSender("system");
                sysAnnouncement.setId(UUIDGenerator.generate());
                //查询内容

                QueryWrapper<ContentInfo> contentInfoQueryWrapper = new QueryWrapper<ContentInfo>();
                contentInfoQueryWrapper.eq("task_id",taskNo).last(" limit 1");
                ContentInfo contentInfo = contentInfoService.getOne(contentInfoQueryWrapper);
                sysAnnouncement.setMsgContent("【任务待办通知】编号："+taskNo +" 标题："+contentInfo.getContentTitle());

                sysAnnouncement.setTitile("【任务待办通知】通知您，任务："+contentInfo.getContentTitle()+"-"+taskNo+"与您有关，请在查看");
                String userIdStr = "";
                List<String> newUserIds = userIds.stream().distinct().collect(Collectors.toList());
                for(String tempId : newUserIds){
                    userIdStr += (tempId+",");
                }
                sysAnnouncement.setUserIds(userIdStr);
                sysAnnouncementService.saveAnnouncement(sysAnnouncement);
            }catch (Exception e){

            }
        });
    }




}
